<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/

/**
 * 博客用户模型，负责数据，增，删，改，查
 * 因为没有博客数据没使用数据库，所以没有继承 Model 类
 */
Class UsersModel extends PublicModel{


	/**
	 * 处理用户注册数据
	 * @param  [type] $arr [接收数据（数组）]
	 * @return [type]      [description]
	 */
	Public function regUsers($array){
		if (Badword::word($array['username']) == '*' || Badword::word($array['user_id']) == '*') {
			return false;
		}
		unset($array['id']);
		unset($array['code']);
		$array['password'] = md5($array['password']);
		$array['regtime'] = date('Y.m.d / H:i:s', time());
		$array['ord'] = count(GetFileList(C('user'))) + 1;
		$dir = C('user').$array['user_id'].'.php';
		if (varfile($dir, $array)) {
			return true;
		}
	}

	/**
	 * 处理用户登陆数据
	 * @param  [type] $arr [接收数据（数组）]
	 * @return [type]      [description]
	 */
	Public function userLogin($array){
		unset($array['code']);
		unset($array['id']);
		$dir = loadfile(C('user').$array['user_id'].'.php');
		$array['password'] = md5($array['password']);
		return ($array['password'] == $dir['password']) ? true : false;
	}


	/**
	 * 用户修改自己的信息
	 * @param  [type] $arr [接收数组（数组）]
	 * @return [type]      [description]
	 */
	Public function userUpdata($arr){
		$dir = C('user').$arr['user_id'].'.php';
		$user = loadfile($dir);
		$user['username'] = $arr['username'];
		$user['password'] = !empty($arr['password']) ? md5($arr['password']) : $user['password'];
		$user['url'] = $arr['url'];
		$user['email'] = $arr['email'];
		$user['msg'] = $arr['msg'];
		if (varfile($dir, $user)) {
			return true;
		}
	}

	/**
	 * 用户删除自己的评论
	 * @param  [type] $pid [评论文件IP]
	 * @param  [type] $fid [评论IP]
	 * @return [type]      [description]
	 */
	Public function delPL($arr){
		$did = $arr['did'];
		$fid = $arr['fid'];
		$iddir = C('pinglun.id');
		$datadir = C('pinglun.data');
		$file = loadfile($iddir.$did.'.php');
		unset($file[$fid]);
		uasort($file, "Post_Sort");
		if (varfile($iddir.$did.'.php', $file)) {
			unlink($datadir.$fid.'.Mark');
			return true;
		}
	}
}